#coding=utf8
import urllib
import re
def getchapter(url,name="unamed",mylog=None):
    "parser html source to generate chapterlist"
    # cretele for tele.zxmh.net
    cretele = re.compile('<li><a href="(.+?)" >(.+?)</a></li>')
    cre = re.compile('<li><a  target="_blank" href="(.+?)" >(.+?)</a></li>')
    tele = False
    if url.find('tele.zxmh.net') != -1:
        tele = True
        myre = cretele
    else:
        myre = cre
    chapterlist = []
    content = ''
    try:
        content = urllib.urlopen(url).read()
        if content:
            for item in myre.findall(content):
                if tele:
                    chapterlist.append(['http://www.zxmh.net'+item[0],item[1].decode('gbk').encode('utf-8')])
                else:
                    chapterlist.append([url+item[0],item[1].decode('gbk').encode('utf-8')])
        return chapterlist
    except  Exception, e:
        if mylog:
            mylog.writeLog(str(e)+'in getchapter','error')
        return None
